#define _CRT_SECURE_NO_WARNINGS 1

#include <vector>
#include <unordered_map>
#include <iostream>
using namespace std;


class Solution {
public:
    int lenLongestFibSubseq(vector<int>& arr)
    {
        int n = arr.size();
        unordered_map<int, int> hash;
        vector<vector<int>> dp(n, vector<int>(n, 2));
        for (int i = 0; i < n; i++)
        {
            hash[arr[i]] = i;
        }
        int ret = 2;
        for (int j = 2; j < n; j++)
        {
            for (int i = 1; i < j; i++)
            {
                int a = arr[j] - arr[i];
                if (hash.count(a) && a < arr[i])
                {
                    dp[i][j] = dp[hash[a]][i] + 1;
                    ret = max(ret, dp[i][j]);
                }
            }
        }

        for (int i = 0; i < dp.size(); i++)
        {
            for (int j = 0; j < dp[0].size(); j++)
            {
                cout << dp[i][j] << " ";
            }
            cout << endl;
        }

        return ret == 2 ? 0 : ret;
    }
};


int main()
{
    vector<int> v = { 2, 4, 7, 8, 9, 10, 14, 15, 18, 23, 32, 50 };
    Solution().lenLongestFibSubseq(v);
    return 0;
}